package elevatronic.view.left.elevators;

import java.util.ArrayList;
import java.util.List;

import elevatronic.models.Elevator;
import elevatronic.view.MPanel;
import elevatronic.view.simulation.ElevatorView;

public class ElevatorPanels extends MPanel{
	private static final long serialVersionUID = 2455355318597061991L;

	public static final int ELEVATOR_PANEL_POSX=7;
	public static final int ELEVATOR_PANEL_POSY=10;

	// list of elevators models
	private List<Elevator> elevators;
	public List<Elevator> getElevators() {
		return elevators;
	}
	public void setElevators(List<Elevator> elevators) {
		this.elevators = elevators;
	}
	

	
	
	//List of elevator panel
	private List<ElevatorPanel> elevatorPanels;
	public List<ElevatorPanel> getElevatorPanels() {
		return elevatorPanels;
	}
	public void setElevatorPanels(List<ElevatorPanel> elevatorPanels) {
		this.elevatorPanels = elevatorPanels;
	}
	
	

	/** 
	 * Constructor
	 * @param wdth width of the panel
	 * @param hght height of the panel
	 */
	public ElevatorPanels(int wdth,int hght, List<ElevatorView> elevatorsView){
		super(wdth,hght);		
	    List<ElevatorPanel> elevatorPanels=new ArrayList<ElevatorPanel>();
	    List<Elevator> elevators = new ArrayList<Elevator>();
	    int i=0;
	    for (ElevatorView elevatorView:elevatorsView){
	    	ElevatorPanel elevatorPanel=new ElevatorPanel(ElevatorPanel.ELEVATOR_PANEL_WIDTH,ElevatorPanel.ELEVATOR_PANEL_HEIGHT,elevatorView);
	    	elevatorPanel.setLocation(ELEVATOR_PANEL_POSX, ELEVATOR_PANEL_POSY+(30+ElevatorPanel.ELEVATOR_PANEL_HEIGHT)*i);
	    	elevatorPanels.add(elevatorPanel);
	    	add(elevatorPanel);
	    	elevators.add(elevatorPanel.getElevator());
	    	i++;
	    }
	    
	    setElevators(elevators);
	    setElevatorPanels(elevatorPanels);	    
	}
	
	

	
	//iteration of the elevator panels
	public void update(int step){
		super.update(step);
		for(ElevatorPanel elevatorPanel:getElevatorPanels()){
			elevatorPanel.update(step);
		}
	}
}
